/**
 * 获取用户当天获取的所有验证码记录
 * @param {String} userid 用户id
 */
const Dayjs = require("dayjs");
const MYSQL = require("../../sql/mysql");
module.exports = function (userid) {
  return new Promise((resolve, reject) => {
    if (!userid) {
      reject({ code: 203, msg: "用户id不能为空" });
      return;
    }
    let date_now = Dayjs(Date.now());
    let day_start = String(date_now.startOf("day").valueOf());
    let day_end = String(date_now.endOf("day").valueOf());
    let querySql = `
  SELECT * FROM verify_code
  WHERE
  user=${userid} and 
  created_date between ${day_start} and ${day_end} 
  `;
    MYSQL.query(querySql, (err, data) => {
      if (err) {
        reject({ code: 500, msg: "查询失败" });
      } else {
        resolve({ code: 0, msg: "查询成功", list: data });
      }
    });
  });
};
